# -*- coding: utf-8 -*-
"""
API文档定义
"""

SIMPLE_DOC = {
    "tags": ["支付系统"],
    "summary": "API接口",
    "description": "API接口说明",
    "responses": {
        "200": {
            "description": "请求成功",
            "schema": {
                "type": "object",
                "properties": {
                    "code": {"type": "integer", "example": 200},
                    "message": {"type": "string", "example": "操作成功"},
                    "data": {"type": "object"}
                }
            }
        }
    }
}


SIMPLE_DOC = {
    "tags": ["API"],
    "summary": "API接口",
    "description": "API接口说明",
    "responses": {
        "200": {
            "description": "请求成功",
            "schema": {
                "type": "object",
                "properties": {
                    "code": {"type": "integer", "example": 200},
                    "message": {"type": "string", "example": "操作成功"},
                    "data": {"type": "object"}
                }
            }
        }
    }
}

# 为兼容性创建通用别名
CREATE_ORDER_DOC = SIMPLE_DOC
GET_ORDER_LIST_DOC = SIMPLE_DOC
GET_ORDER_DETAIL_DOC = SIMPLE_DOC
UPDATE_ORDER_DOC = SIMPLE_DOC
DELETE_ORDER_DOC = SIMPLE_DOC
CANCEL_ORDER_DOC = SIMPLE_DOC
GET_USER_ORDERS_DOC = SIMPLE_DOC

# 管理员相关
ADMIN_GET_ORDER_LIST_DOC = SIMPLE_DOC
ADMIN_UPDATE_ORDER_DOC = SIMPLE_DOC
ADMIN_DELETE_ORDER_DOC = SIMPLE_DOC
ADMIN_ORDER_STATS_DOC = SIMPLE_DOC

# 活动相关
CREATE_ACTIVITY_DOC = SIMPLE_DOC
GET_ACTIVITY_LIST_DOC = SIMPLE_DOC
GET_ACTIVITY_DETAIL_DOC = SIMPLE_DOC
UPDATE_ACTIVITY_DOC = SIMPLE_DOC
DELETE_ACTIVITY_DOC = SIMPLE_DOC
JOIN_ACTIVITY_DOC = SIMPLE_DOC

# 支付相关
CREATE_PAYMENT_DOC = {
    "tags": ["支付管理"],
    "summary": "创建支付订单",
    "description": "为预约订单创建支付订单\n\n**🔐 需要用户Token认证**",
    "security": [{"Bearer": []}],
    "parameters": [
        {
            "name": "body",
            "in": "body",
            "required": True,
            "description": "支付创建参数",
            "schema": {
                "type": "object",
                "required": ["orderId"],
                "properties": {
                    "orderId": {
                        "type": "integer",
                        "description": "预约订单ID",
                        "example": 1
                    },
                    "paymentMethod": {
                        "type": "string",
                        "description": "支付方式：wechat=微信支付",
                        "example": "wechat",
                        "default": "wechat"
                    }
                }
            }
        }
    ],
    "responses": {
        "200": {
            "description": "支付订单创建成功",
            "schema": {
                "type": "object",
                "properties": {
                    "code": {
                        "type": "integer",
                        "example": 200,
                        "description": "状态码"
                    },
                    "message": {
                        "type": "string",
                        "example": "支付订单创建成功",
                        "description": "响应消息"
                    },
                    "data": {
                        "type": "object",
                        "description": "支付信息",
                        "properties": {
                            "paymentId": {
                                "type": "integer",
                                "example": 1,
                                "description": "支付记录ID"
                            },
                            "paymentNo": {
                                "type": "string",
                                "example": "PAY20240115123456789012",
                                "description": "支付订单号"
                            },
                            "amount": {
                                "type": "number",
                                "example": 100.00,
                                "description": "支付金额"
                            },
                            "prepayId": {
                                "type": "string",
                                "example": "wx123456789012345678901234567890",
                                "description": "微信预支付ID"
                            },
                            "timeStamp": {
                                "type": "string",
                                "example": "1642231234",
                                "description": "时间戳"
                            },
                            "nonceStr": {
                                "type": "string",
                                "example": "abc123def456",
                                "description": "随机字符串"
                            },
                            "package": {
                                "type": "string",
                                "example": "prepay_id=wx123456789012345678901234567890",
                                "description": "扩展字段"
                            },
                            "signType": {
                                "type": "string",
                                "example": "RSA",
                                "description": "签名类型"
                            },
                            "paySign": {
                                "type": "string",
                                "example": "ABC123DEF456...",
                                "description": "支付签名"
                            }
                        }
                    }
                }
            }
        },
        "400": {
            "description": "创建支付失败",
            "schema": {
                "type": "object",
                "properties": {
                    "code": {"type": "integer", "example": 400},
                    "message": {"type": "string", "example": "订单不存在或已支付"}
                }
            }
        }
    }
}

PAYMENT_NOTIFY_DOC = {
    "tags": ["支付管理"],
    "summary": "支付结果通知",
    "description": """接收第三方支付平台的支付结果通知。

**🎯 功能特点：**
- 验证支付平台签名确保数据安全
- 更新订单和支付状态
- 生成入场签到码
- 创建入场记录
- 防重复处理确保幂等性

**⚠️ 重要说明：**
- 此接口仅供支付平台回调使用
- 处理成功返回SUCCESS，失败返回FAIL
- 支付成功后会自动更新订单状态并生成签到码

**💡 处理流程：**
- 验证回调数据签名和完整性
- 更新支付记录状态
- 更新订单状态为已支付
- 生成唯一签到码""",
    "parameters": [
        {
            "name": "body",
            "in": "body",
            "required": True,
            "description": "支付通知数据（微信支付平台发送的加密数据）",
            "schema": {
                "type": "object",
                "description": "微信支付通知数据（加密）"
            }
        }
    ],
    "responses": {
        "200": {
            "description": "通知处理成功",
            "schema": {
                "type": "object",
                "properties": {
                    "code": {"type": "string", "example": "SUCCESS"},
                    "message": {"type": "string", "example": "OK"}
                }
            }
        },
        "400": {
            "description": "通知处理失败",
            "schema": {
                "type": "object",
                "properties": {
                    "code": {"type": "string", "example": "FAIL"},
                    "message": {"type": "string", "example": "签名验证失败"}
                }
            }
        }
    }
}

GET_PAYMENT_STATUS_DOC = {
    "tags": ["支付管理"],
    "summary": "查询支付状态",
    "description": "查询支付订单的状态",
    "parameters": [
        {
            "name": "payment_id",
            "in": "path",
            "type": "integer",
            "required": True,
            "description": "支付记录ID",
            "example": 1
        }
    ],
    "responses": {
        "200": {
            "description": "查询成功",
            "schema": {
                "type": "object",
                "properties": {
                    "code": {
                        "type": "integer",
                        "example": 200,
                        "description": "状态码"
                    },
                    "message": {
                        "type": "string",
                        "example": "查询成功",
                        "description": "响应消息"
                    },
                    "data": {
                        "type": "object",
                        "description": "支付状态信息",
                        "properties": {
                            "id": {
                                "type": "integer",
                                "example": 1,
                                "description": "支付记录ID"
                            },
                            "payment_no": {
                                "type": "string",
                                "example": "PAY20240115123456789012",
                                "description": "支付订单号"
                            },
                            "order_id": {
                                "type": "integer",
                                "example": 1,
                                "description": "关联的预约订单ID"
                            },
                            "amount": {
                                "type": "number",
                                "example": 100.00,
                                "description": "支付金额"
                            },
                            "status": {
                                "type": "integer",
                                "example": 1,
                                "description": "支付状态：0=待支付，1=支付成功，2=支付失败，3=已退款"
                            },
                            "status_text": {
                                "type": "string",
                                "example": "支付成功",
                                "description": "状态文本"
                            },
                            "payment_method": {
                                "type": "string",
                                "example": "wechat",
                                "description": "支付方式"
                            },
                            "transaction_id": {
                                "type": "string",
                                "example": "4200001234567890123456789012",
                                "description": "第三方交易号"
                            },
                            "paid_at": {
                                "type": "string",
                                "example": "2024-01-15 10:30:00",
                                "description": "支付时间"
                            },
                            "created_at": {
                                "type": "string",
                                "example": "2024-01-15 10:00:00",
                                "description": "创建时间"
                            }
                        }
                    }
                }
            }
        },
        "404": {
            "description": "支付记录不存在",
            "schema": {
                "type": "object",
                "properties": {
                    "code": {"type": "integer", "example": 404},
                    "message": {"type": "string", "example": "支付记录不存在"}
                }
            }
        }
    }
}

QUERY_PAYMENT_DOC = {
    "tags": ["支付管理"],
    "summary": "查询支付方式",
    "description": "获取系统支持的支付方式列表\n\n**🔐 需要用户Token认证**",
    "security": [{"Bearer": []}],
    "responses": {
        "200": {
            "description": "查询成功",
            "schema": {
                "type": "object",
                "properties": {
                    "code": {
                        "type": "integer",
                        "example": 200,
                        "description": "状态码"
                    },
                    "message": {
                        "type": "string",
                        "example": "查询成功",
                        "description": "响应消息"
                    },
                    "data": {
                        "type": "object",
                        "description": "支付方式信息",
                        "properties": {
                            "paymentMethods": {
                                "type": "array",
                                "description": "支付方式列表",
                                "items": {
                                    "type": "object",
                                    "properties": {
                                        "method": {
                                            "type": "string",
                                            "example": "wechat",
                                            "description": "支付方式代码"
                                        },
                                        "name": {
                                            "type": "string",
                                            "example": "微信支付",
                                            "description": "支付方式名称"
                                        },
                                        "icon": {
                                            "type": "string",
                                            "example": "https://example.com/wechat-icon.png",
                                            "description": "图标URL"
                                        },
                                        "enabled": {
                                            "type": "boolean",
                                            "example": True,
                                            "description": "是否启用"
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}

# 横幅相关
GET_BANNER_LIST_DOC = SIMPLE_DOC
CREATE_BANNER_DOC = SIMPLE_DOC
UPDATE_BANNER_DOC = SIMPLE_DOC
DELETE_BANNER_DOC = SIMPLE_DOC

# 管理员相关
ADMIN_LOGIN_DOC = SIMPLE_DOC
GET_ADMIN_INFO_DOC = SIMPLE_DOC

# 仪表盘相关
GET_DASHBOARD_STATS_DOC = SIMPLE_DOC
GET_REVENUE_CHART_DOC = SIMPLE_DOC
GET_ORDER_CHART_DOC = SIMPLE_DOC

# 其他可能缺失的支付相关
REFUND_PAYMENT_DOC = SIMPLE_DOC
WECHAT_PAYMENT_DOC = SIMPLE_DOC

# 手动支付回调接口文档
MANUAL_PAYMENT_NOTIFY_DOC = {
    'tags': ['Payment'],
    'summary': '手动触发支付成功（测试专用）',
    'description': '提供订单号（order_no），直接将订单和关联的支付记录（如果不存在则创建）标记为支付成功。此接口仅用于开发和测试环境。',
    'parameters': [
        {
            'name': 'body',
            'in': 'body',
            'required': True,
            'schema': {
                'type': 'object',
                'properties': {
                    'order_no': {
                        'type': 'string',
                        'description': '要标记为成功的订单号',
                        'example': 'ORD20240726123456GHIJKL'
                    }
                },
                'required': ['order_no']
            }
        }
    ],
    'responses': {
        '200': {
            'description': '手动处理成功',
            'schema': {
                'type': 'object',
                'properties': {
                    'code': {'type': 'integer', 'example': 200},
                    'message': {'type': 'string', 'example': '手动支付回调处理成功'}
                }
            }
        },
        '400': {
            'description': '请求参数错误，如缺少order_no',
        },
        '404': {
            'description': '订单未找到',
        }
    }
}
